using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls ;

public partial class pages_login : System.Web.UI.Page
{
    AccountDAO daoAccount = new AccountDAO();
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        if (Request.UrlReferrer != null) ViewState["pre_page"] = Request.UrlReferrer.ToString();
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        MemberInfo member = new MemberInfo();
        string username = txtUsername.Text;
        string password = txtPassword.Text;
        member = daoAccount.GetAccount(username);
        if (username == "")
        {
            lblMessage.Text = "Username cannot be empte";
            return;
        }
        if (member.Username != username)
        {
            lblMessage.Text = "Invalid username";
            return;
        }
        if (member.Password != password)
        {
            lblMessage.Text="Invalid password. Please try again";
            return;
        }      
            Session["user"] = username;
            Session["logedin"] = true;
           // Response.Redirect("Index.aspx");
            if (ViewState["pre_page"] != null)
            {
                string pre_page = ViewState["pre_page"].ToString();
                Response.Redirect(pre_page);
            }


      
    }
}
